void menu()
{
	keypad.getKey();
	if(keySelect != '\0') 
	{
		if(keySelect == OK){

		}
		else if(keySelect == CANCEL)
		{
			if(currentMenu != mnMain && currentFunction != -1)
				menuMain();
		}
		else if(currentFunction != -1){
			uint8_t numKey = keyPreviuos - 48;
			if(numKey <= numFunction && numKey >= 1)
				selectMenu(numKey);
		}
		keySelect = '\0';
	}
}
void menuMain(){
	setFunctionName("Quan ly de thi", 0);
	setFunctionName("Trien khai thi", 1);
	setFunctionName("Cai dat he thong", 2);
	initMenu("CHUC NANG CHINH", mnMain, 3);
}
void menuManagementExamQuestion()
{
	setFunctionName("Tao nhom de thi", 0);
	setFunctionName("Sua dap an de thi", 1);
	setFunctionName("Xoa nhom de thi", 2);
	setFunctionName("Tai lai phien cu", 3);
	initMenu("QUAN LY DE THI", mnManagementExamQuestion, 4);
}
void menuExamQuestion()
{
	setFunctionName("Tao phien thi moi", 0);
	setFunctionName("Tai lai phien cu", 1);
	setFunctionName("Truy van ca thi", 2);
	initMenu("TRIEN KHAI THI", mnExam, 3);
}
void menuSetupSystem()
{
	setFunctionName("Cai dat thoi gian", 0);
	setFunctionName("Kiem tra may tram", 1);
	setFunctionName("Dang ky may tram", 2);
	setFunctionName("Huy may tram", 3);
	setFunctionName("Truy cap he thong", 4);
	initMenu("CAI DAT HE THONG", mnSetupSystem, 5);
}
void initMenu(String title, uint8_t currMenu, uint8_t numberFuntion)
{
	titleMenu = title;
	currentMenu = currMenu;
	numFunction = numberFuntion;	
	currentFunction = -1;
	drawMenu();
}
void drawMenu(){
	drawTitleMenu(titleMenu, (currentMenu != 0) + 1);
	uint8_t i;
	for(i = 1; i <= numFunction; i++)
		drawFunction(i);
}
void drawFunction(int index){
	uint8_t x, y;
	x = distance;
	y = 2 + 2*distance + (fontHeight + 3)*index;
	GLCD.DrawRect(x - 1, y - 1, 7, 8, BLACK);	
	GLCD.SelectFont(FontNew); 
	textShow((String)index, x, y);
	GLCD.SelectFont(SystemFont5x7); 
	textShow(functionName[index - 1], x + fontWidth + 4, y); 
}
void setFunctionName(String content, int index){
	uint8_t i, len;
	len = content.length();
	for(i = 0; i < len; i++) functionName[index][i] = content[i];
	functionName[index][len] = '\0';
}
void selectMenu(uint8_t numKey){
	if(currentMenu == mnMain)
	{
		if(numKey == mnManagementExamQuestion)
			menuManagementExamQuestion();
		else if(numKey == mnExam)
			menuExamQuestion();
		else if(numKey == mnSetupSystem)
			menuSetupSystem();
	}
	else if(currentMenu == mnManagementExamQuestion)
	{
		if(numKey == mnCreateExamQuestion)
			menuCreateExamQuestion();
		else if(numKey == mnFixExamQuestion)
			menuFixExamQuestion();
		else if(numKey == mnDelExamQuestion)
			menuDelExamQuestion();
		else if(numKey == mnLoadingTurnOld)
			menuLoadingTurnOld();
	}
	else if(currentMenu == mnExam)
	{
		if(numKey == mnCreateExamTurn)
			menuCreateExamTurn();
		else if(numKey == mnLoadingExamTurn)
			menuLoadingExamTurn();
		else if(numKey == mnQueryExam)
			menuQueryExam();
	}
	else if(currentMenu == mnSetupSystem)
	{
		if(numKey == mnSetupTime)
			menuSetupTime();
		else if(numKey == mnCheckClient)
			menuCheckClient();
		else if(numKey == mnRegisterClient)
			menuRegisterClient();
		else if(numKey == mnDestroyClient)
			menuDestroyClient();
		else if(numKey == mnAccessSystem)
			menuAccessSystem();
	}
}
void drawTitleMenu(String title, uint8_t level){
	GLCD.ClearScreen();
	textShowCenter(title, distance, 2*distance, width);
	GLCD.DrawLine(0, fontHeight + 3, width, fontHeight + 3);
	uint8_t i;
	for(i = 0; i < 3; i++)
		GLCD.DrawLine(i, 0, i, 9);
	if(level >= 2) 
		for(i = 0; i < 3; i++)
			GLCD.DrawLine(i + 3, 3, i + 3, 9);
	if(level == 3) 
		for(i = 0; i < 3; i++)
			GLCD.DrawLine(i + 6, 6, i + 6, 9);
}
void changeLineInputText(){
	while(true){					
		if(keySelect == DOWN) indexRowInput = (indexRowInput + 1)%numInputText;
		else if(indexRowInput == 0) indexRowInput = numInputText - 1;
		else indexRowInput = (indexRowInput - 1)%numInputText;
		if(inputText[indexRowInput].textMode != LABELMODE) break;
	}
	textShow((String)' ', xCursor - 1, yCursor + 1);	
	indexCursor = inputText[indexRowInput].content.length();	
	initCursor();
	if(indexCursor != 0) indexCursor--;
	keyMode = inputText[indexRowInput].keyMode;
}
void initCursor()
{
	xCursor = (inputText[indexRowInput].label.length() + 1)*(fontWidth + 1) + distance + indexCursor*(fontWidth + 1);
	yCursor = 4*distance + (fontHeight + 3)*(indexRowInput + 1);
	GLCD.DrawLine(xCursor, yCursor + 9, xCursor + fontWidth - 1, yCursor + 9);
}
void changeIndexCursor()
{
	timeStartPress = 0;
	if(inputText[indexRowInput].content.charAt(indexCursor) == '\0') return;
	textShow((String)' ', xCursor - 1, yCursor + 1);	
	indexCursor++;
	initCursor();
	drawContentInput();
}
void delCharInputContent()
{
	if(indexCursor <= 0) return;
	textShow((String)' ', xCursor - 1, yCursor);	
	textShow((String)' ', xCursor - 2 - fontWidth, yCursor);	
	textShow((String)' ', xCursor - 1, yCursor + 1);	
	indexCursor--;
	initCursor();
	inputText[indexRowInput].content = inputText[indexRowInput].content.substring(0, inputText[indexRowInput].content.length() - 1);
	drawContentInput();
}
void delAllInputContent(){
	if(indexCursor == 0)return;
	uint8_t i, len, x, y;
	x = (inputText[indexRowInput].label.length() + 1)*(fontWidth + 1);
	y = 4*distance + (fontHeight + 3)*(indexRowInput + 1);
	len = inputText[indexRowInput].content.length();
	for(i = 0; i < len ; i++) inputText[indexRowInput].content.setCharAt(i, ' ');
	textShow((String)' ', xCursor - 1, yCursor + 1);
	textShow(inputText[indexRowInput].content, x, y);
	indexCursor = 0;
	initCursor();
	inputText[indexRowInput].content = "";
}
void drawLabel(String content, uint8_t row)
{
	uint8_t y, len;
	len = content.length();
	y = 4*distance + (fontHeight + 3)*(row + 1);
	textShow(content, distance, y);	
	GLCD.SetDot(2*distance + len*(fontWidth + 1), y + 3, BLACK);
	GLCD.SetDot(2*distance + len*(fontWidth + 1), y + 7, BLACK);
}
void drawContentInput()
{
	uint8_t x, y;
	x = (inputText[indexRowInput].label.length() + 1)*(fontWidth + 1);
	y = 4*distance + (fontHeight + 3)*(indexRowInput + 1);
	if(inputText[indexRowInput].textMode == PASSMODE)
	{
		uint8_t i, len;
		String content;
		content = ""; 
		len = inputText[indexRowInput].content.length();
		for(i = 0; i < len; i++) content += '*';
		content.setCharAt(indexCursor, inputText[indexRowInput].content.charAt(indexCursor));
		textShow(content, x, y);
	}
	else textShow(inputText[indexRowInput].content, x, y);
}
void addCharInputContent()
{	
	if(inputText[indexRowInput].content.charAt(indexCursor) == '\0') 
		inputText[indexRowInput].content += keySelect;
	else inputText[indexRowInput].content.setCharAt(indexCursor, keySelect);
	drawContentInput();
}
void drawInputLabel()
{
	indexCursor = 0;
	uint8_t i;	
	for(i = 0; i < numInputText; i++)
		drawLabel(inputText[i].label, i);		
}
void initInputText(String labelName, String content, uint8_t index, uint8_t textModeName, uint8_t keyModeName)
{
	inputText[index].label = labelName;
	inputText[index].content = content;
	inputText[index].textMode = textModeName;
	inputText[index].keyMode = keyModeName;
}
void initFunction(String titleMenu, uint8_t levelMenu, uint8_t indexRowInputSart, uint8_t numberInputText)
{
	numInputText = numberInputText;
	redrawnFunction(titleMenu, levelMenu, indexRowInputSart);
	exitFunction = false;
	keyMode = inputText[indexRowInput].keyMode;
	keySelect = '\0';
}
void checkKey(){
	if(timeStartPress != 0 && (millis() - timeStartPress > timeDistance))
	{
		changeIndexCursor();
	}
	if(keySelect == DELETE)
	{
		if(keyState == HOLD) 
		{
			delAllInputContent();
		}
		else 
		{
			delCharInputContent();						
		}
	}
	else if(keySelect == UP || keySelect == DOWN)
		changeLineInputText();
	else if(keySelect != '\0')
		addCharInputContent(); 
}
uint8_t drawMessage(String message, uint8_t typeMessage)
{
	GLCD.ClearScreen();
	uint8_t len;
	len = message.length();
	if(len > 42)
	{
		uint8_t i, j;
		i = 21;
		while(true) if(message.charAt(--i) == ' ') break;
		j = 42;
		while(true) if(message.charAt(--j) == ' ') break;
		textShowCenter(message.substring(0, ++i), 0, 10, width);
		textShowCenter(message.substring(i, ++j), 0, 12 + fontHeight, width);
		textShowCenter(message.substring(j, len), 0, 14 + 2*fontHeight, width);
	} 
	else if(len > 21)
	{
		uint8_t i;
		i = 21;
		while(true) if(message.charAt(--i) == ' ') break;
		textShowCenter(message.substring(0, i), 0, 10, width);
		textShowCenter(message.substring(i, len), 0, 12 + fontHeight, width);
	} 
	else textShowCenter(message, distance, 10, width);
	keySelect = '\0';
	GLCD.DrawRect(0, 0, width, height, BLACK);
	if(typeMessage == OKTYPE)
	{
		GLCD.DrawRect(44, 40, 40, 10, BLACK);
		textShow("OK", 58, 41);
	}
	else {
		GLCD.DrawRect(16, 40, 40, 10, BLACK);
		textShow("OK", 30, 41);
		GLCD.DrawRect(72, 40, 40, 10, BLACK);
		textShow("CANCEL", 74, 41);
	}
	while(true)
	{
		keypad.getKey();
		if(keySelect == OK || (keySelect == CANCEL && typeMessage == OKCANCELTYPE))
		{
			char key = keySelect;
			keySelect = '\0';
			return key;
		}
	}
}
uint8_t convertNum(String content) 
{
	uint8_t num, i, len;
	num = 0;
	len = content.length();
	for(i = 0; i < len; i++) num = num*10 + content.charAt(i) - 48;
	return num;
}
void redrawnFunction(String titleMenu, uint8_t levelMenu, uint8_t indexLineCurrent)
{
	uint8_t i;
	drawTitleMenu(titleMenu, levelMenu);
	drawInputLabel();
	indexCursor = -1; //Khi kieu nhap la password thi ky tu tai indexCursor cua phan nhap noi dung khong duoc gan gia tri ky tu.
	for(i = 0; i < numInputText; i++) 
	{
		indexRowInput = i;
		drawContentInput();
	}
	indexRowInput = indexLineCurrent;
	indexCursor = inputText[indexRowInput].content.length();
	if(indexRowInput < numFunction) initCursor();
}
void delCursorCell(String answerContent, uint8_t questionIndex, uint8_t indexCursorCell)
{
	uint8_t row, col, x, y;
	row = (questionIndex%15)%3;
	col = (questionIndex%15)/3;
	x = distance + 2*(fontWidth + 1) + 2 + row*40;
	y = 12 + col*10;
	textShow(" ", x + indexCursorCell*(fontWidth + 1), y + 2);//xoa ky tu gach duoi
	textShow(answerContent,x , y);
}
void drawCursorCell(String answerContent, uint8_t questionIndex, uint8_t indexCursorCell)
{
	uint8_t row, col, x, y;
	row = (questionIndex%15)%3;
	col = (questionIndex%15)/3;
	x = distance + 2*(fontWidth + 1) + 2 + row*40;
	y = 12 + col*10;
	GLCD.DrawLine(x + indexCursorCell*(fontWidth + 1) + 1, y + 9, x + indexCursorCell*(fontWidth + 1) + 5, y + 9, BLACK);
	if(indexCursorCell != 0) textShow(" ", x + (indexCursorCell - 1)*(fontWidth + 1), y + 2);
	textShow(answerContent,x , y);
}
void drawCellInput(String answerContent, uint8_t questionIndex)
{
	String question = "";
	uint8_t row, column;
	row = (questionIndex%15)%3;
	column = (questionIndex%15)/3;
	if(questionIndex < 9) question = "0" + (String)(questionIndex + 1);
	else question = (String)(questionIndex + 1);
	textShow(question, distance + 40*row, 12 + column*10);
	GLCD.SetDot(distance + 40*row + 2*(fontWidth + 1) + 1, 15 + column*10, BLACK);
	GLCD.SetDot(distance + 40*row + 2*(fontWidth + 1) + 1, 19 + column*10, BLACK);
	textShow(answerContent, distance + 2*(fontWidth + 1) + 2 + row*40, 12 + column*10);
}
void drawInputAnswer(String answerContent[], uint8_t codeExam, uint8_t startQuestion, uint8_t endQuestion){
	drawTitleMenu("Dap an ma de: " + (String)codeExam, 3);
	textShow("`", width - fontWidth - 2, 7);
	textShow("^", width - fontWidth - 2, height - 8);
	GLCD.DrawRect(0, 10, width - 1, height - 10);
	uint8_t columnWidth = 40;
	GLCD.DrawLine(columnWidth, 10, columnWidth, height);
	GLCD.DrawLine(2*columnWidth, 10, 2*columnWidth, height);
	GLCD.DrawLine(3*columnWidth, 10, 3*columnWidth, height);
	uint8_t questionIndex;
	for(questionIndex = startQuestion; questionIndex < endQuestion; questionIndex++)
		drawCellInput(answerContent[questionIndex], questionIndex);
}
bool drawGuiInputAnswer(uint8_t codeExam,uint8_t numQuestion)
{
	bool exitInputAnswer;
	exitInputAnswer = false;
	int8_t indexCursorCell, questionIndex;
	String answerContent[100], answerContentTmp;
	indexCursorCell = 0;
	answerContentTmp = "";
	questionIndex = numQuestion;//Dieu kien de ve giao dien nhap dap an trong lan lap dau tien
	keySelect = DOWN;//Trong lan lap dau tien se kiem tra phim up de ve giao dien nhap dap an
	while (!exitInputAnswer)
	{
		char key = keypad.getKey();
		if(keySelect == OK){
			answerContent[questionIndex] = answerContentTmp;
			uint8_t i;
			bool isDrawInputAnswer;
			isDrawInputAnswer = false; //kiem tra co ve lai giao dien nhap dap an hay khong?
			for(i = 0; i < numQuestion; i++)
			{
				if(answerContent[i] == "") 
				{
					questionIndex = i;
					drawMessage("Dap an cau '" + (String)(questionIndex + 1) + "' rong. Hay nhap lai!", OKTYPE);
					isDrawInputAnswer = true;
					answerContentTmp = "";
					indexCursorCell = 0;
					break;
				}
			}
			if(i == numQuestion) //kiem tra khong co dap an nao rong
			{
				uint8_t resultMessage;
				resultMessage = drawMessage("Ban co muon luu dap dap an cua ma de khong?", OKCANCELTYPE);
				if(resultMessage == OK)
					exitInputAnswer = true;
				else isDrawInputAnswer = true;
			}
			if(isDrawInputAnswer)
			{
				uint8_t startIndex, endIndex;
				startIndex = questionIndex - (questionIndex % 15);
				if(startIndex + 15 > numQuestion) endIndex = numQuestion;
				else endIndex = startIndex + 15;
				drawInputAnswer(answerContent, codeExam, startIndex, endIndex);
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);
			}
		}
		else if(keySelect == CANCEL){
			uint8_t resultMessage;
			resultMessage = drawMessage("Ban co muon thoat khong?", OKCANCELTYPE);
			if(resultMessage == OK)
			{
				menuManagementExamQuestion();
				return false;
			}
			else 
			{
				uint8_t startIndex, endIndex;
				startIndex = questionIndex - (questionIndex % 15);
				if(startIndex + 15 > numQuestion) endIndex = numQuestion;
				else endIndex = startIndex + 15;
				drawInputAnswer(answerContent, codeExam, startIndex, endIndex);
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);
			}
		}else if(keySelect == DOWN){
			answerContent[questionIndex] = answerContentTmp;
			delCursorCell(answerContentTmp, questionIndex, indexCursorCell);
			questionIndex++;			
			if(questionIndex >= numQuestion) 
				questionIndex = 0;
			indexCursorCell = answerContent[questionIndex].length();
			if(questionIndex % 15 == 0)
			{
				//Ve lai giao dien nhap dap an khi qua trang.
				uint8_t endIndex;
				if(questionIndex + 15 > numQuestion) endIndex = numQuestion;
				else endIndex = questionIndex + 15;
				drawInputAnswer(answerContent, codeExam, questionIndex, endIndex);
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);
			}
			else
			{
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);//Dua contro sang o khac
			}
			answerContentTmp = answerContent[questionIndex];//Gia tri cua dap an o moi duoc luu tru tam thoi trong bien answerContentTmp
		}
		else if(keySelect == UP){
			answerContent[questionIndex] = answerContentTmp;
			delCursorCell(answerContentTmp, questionIndex, indexCursorCell);
			questionIndex--;			
			if(questionIndex < 0) 
				questionIndex = numQuestion - 1;
			indexCursorCell = answerContent[questionIndex].length();
			if((questionIndex + 1) % 15 == 0 || questionIndex == numQuestion - 1)
			{
				uint8_t startIndex;
				startIndex = questionIndex - (questionIndex%15);
				drawInputAnswer(answerContent, codeExam, startIndex, questionIndex + 1);
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);
			}
			else
			{
				drawCursorCell(answerContent[questionIndex], questionIndex, indexCursorCell);
			}
			answerContentTmp = answerContent[questionIndex];//Gia tri cua dap an o moi duoc luu tru tam thoi trong bien answerContentTmp
		}
		else if(keySelect == DELETE){
			if(indexCursorCell > 0){
				delCursorCell(answerContentTmp, questionIndex, indexCursorCell);
				indexCursorCell--;
				answerContentTmp.setCharAt(indexCursorCell, ' '); //Xoa ky tu cuoi cung cua answerContentTmp
				drawCursorCell(answerContentTmp, questionIndex, indexCursorCell);
				answerContentTmp = answerContentTmp.substring(0, indexCursorCell);
			}
		}
		else if(keySelect != '\0' && keyPreviuos > 48 && keyPreviuos < 53)
		{
			char key;
			key = (char)(keyPreviuos + 16);//chuyen so sang chu hoa(1->4 se tuong ung voi A->D).	
			if(indexCursorCell < 3 && answerContentTmp.indexOf(key) == -1) //Mot cau hoi chi co toi da 3 dap an va cac dap an phai khac nhau
			{
				answerContentTmp += key;
				indexCursorCell++;
				drawCursorCell(answerContentTmp, questionIndex, indexCursorCell);
			}
		}
		keySelect = '\0';
	}
	return true;
}
void menuCreateExamQuestion()
{
	uint8_t id;
	id = random(99);
	initInputText("", (String)id, 0, LABELMODE, NORMALMODE);
	initInputText("Ten", "", 1, INPUTMODE, NORMALMODE);
	initInputText("Mat khau", "", 2, PASSMODE, NORMALMODE);
	initInputText("Xac nhan", "", 3, PASSMODE, NORMALMODE);
	initFunction("Tao nhom de thi", 3, 1, 4);
	long address;
	DataFlash dataFlash;
	dataFlash = DataFlash();
	if(dataFlash.DF_Ghi_Slot((uint8_t *) id, sizeof(id), address) == false)
	Serial.println("khong luu duoc");
	uint8_t readContent;
	String content = "";
	Serial.println(address, HEX);
	dataFlash._flash->readBytes(address, (uint8_t*)&readContent, 1);
	content += (String)readContent;
	Serial.println("id: " + content);
	while(!exitFunction)
	{
		keypad.getKey();
		if(keySelect == OK)
		{
			uint8_t i;
			for(i = 0; i < numFunction; i++)
			{
				if(inputText[i].content == "")
				{
					drawMessage("Co truong trong, hay nhap lai!", OKTYPE);
					redrawnFunction("Tao nhom de thi", 3, indexRowInput);
					break;
				}
			}
			if(i < numFunction) continue; // neu co dong nhap nao trong thi tiep tuc vong lap nhap lai.
			if(inputText[2].content != inputText[3].content) 
			{
				drawMessage("Mat khau khong trung nhau!", OKTYPE);
				inputText[2].content = "";
				inputText[3].content = "";
				redrawnFunction("Tao nhom de thi", 3, 2);
			}
			else exitFunction = true;	
		}
		else if(keySelect == CANCEL)
		{
			uint8_t resultMessage;
			resultMessage = drawMessage("Ban co muon thoat khong?", OKCANCELTYPE);
			if(resultMessage == OK)
			{
				menuManagementExamQuestion();
				return;
			}
			else 
				redrawnFunction("Tao nhom de thi", 3, indexRowInput);
		}
		else checkKey();
		keySelect = '\0';
	}
	initInputText("So de", "", 0, INPUTMODE, NUMBERMODE);
	initInputText("So cau hoi", "", 1, INPUTMODE, NUMBERMODE);
	initInputText("Thoi gian thi", "", 2, INPUTMODE, NUMBERMODE);
	initFunction("Thong tin nhom de", 3, 0, 3);
	while(!exitFunction)
	{
		keypad.getKey();
		if(keySelect == OK)
		{			
			uint8_t i;
			for(i = 0; i < numFunction; i++)
			{
				if(inputText[i].content == "")
				{
					drawMessage("Co truong trong, hay nhap lai!", OKTYPE);
					redrawnFunction("Thong tin nhom de", 3, indexRowInput);
					break;
				}
			}
			if(i >= numFunction) exitFunction = true;// neu khong co dong nhap nao rong thi chuyen sang chuc nang moi.
		}
		else if(keySelect == CANCEL)
		{
			uint8_t resultMessage;
			resultMessage = drawMessage("Ban co muon thoat khong?", OKCANCELTYPE);
			if(resultMessage == OK)
			{
				menuManagementExamQuestion();
				return;
			}
			else 
				redrawnFunction("Thong tin nhom de", 3, indexRowInput);
		}
		else checkKey();
		keySelect = '\0';
	}
	uint8_t numCodeExam, countCodeExam, numQuestion, listCodeExam[99];
	countCodeExam = 0;
	numCodeExam = convertNum(inputText[0].content);
	numQuestion = convertNum(inputText[1].content);
	while(countCodeExam < numCodeExam)
	{
		initInputText("Ma de", "", 0, INPUTMODE, NUMBERMODE);
		initFunction("Nhap ma de thi", 3, 0, 1);
		while(!exitFunction)
		{
			keypad.getKey();
			if(keySelect == OK){		
				uint8_t codeExam;
				codeExam = convertNum(inputText[0].content);
				if(codeExam == 0)
				{
					drawMessage("Ma de khong hop le, hay nhap lai!", OKTYPE);
					redrawnFunction("Nhap ma de thi", 3, 0);
					continue;
				}
				listCodeExam[countCodeExam] = codeExam;
				if(drawGuiInputAnswer(codeExam, numQuestion) == false) countCodeExam = numQuestion;//neu gia tri tra ve la false thi thoat khoi vong lap nhap ma de.
				countCodeExam++;
				exitFunction = true;
			}
			else if(keySelect == CANCEL){
				uint8_t resultMessage;
				resultMessage = drawMessage("Ban co muon thoat khong?", OKCANCELTYPE);
				if(resultMessage == OK)
				{
					menuManagementExamQuestion();
					return;
				}
				else 
					redrawnFunction("Ma so de thi", 3, 0);
			}
			else checkKey();
			keySelect = '\0';
		}
	}
	drawMessage("Tao nhom de thanh cong", OKTYPE);
	initInputText("Ma nhom de", (String)id, 0, LABELMODE, NORMALMODE);
	initInputText("So luong cau/de", (String)numQuestion, 1, LABELMODE, NORMALMODE);
	String listCodeExamStr = "";
	uint8_t index;
	for(index = 0; index < numCodeExam; index++)
		if(listCodeExam[index] != NULL) listCodeExamStr += (String)listCodeExam[index] + ",";
	initInputText("Cac ma de hop le", listCodeExamStr, 2, LABELMODE, NORMALMODE);
	initFunction("Thong tin nhom de", 3, 4, 3);//chi so hang bat dau lon hon so hang nhap vao de khong ve control.
	while(!exitFunction)
	{
		keypad.getKey();
		if(keySelect == OK || keySelect == CANCEL)
		{
			menuManagementExamQuestion();
			return;
		}
	}

}
void menuFixExamQuestion()
{
	uint8_t id;
	initInputText("Id", "", 0, INPUTMODE, NORMALMODE);
	initInputText("Mat khau", "", 1, PASSMODE, NORMALMODE);
	initFunction("Sua dap an de thi", 3, 0, 2);
	while(!exitFunction)
	{
		keypad.getKey();
		if(keySelect == OK)
		{
			exitFunction = true;	
		}
		else if(keySelect == CANCEL)
		{
			menuManagementExamQuestion();
			return;
		}
		else checkKey();
		keySelect = '\0';
	}
	uint8_t numQuestion, listCodeExam[99];
	bool exitFixCodeExam;
	exitFixCodeExam = false;
	while(!exitFixCodeExam)
	{
		initInputText("Ma de", "", 0, INPUTMODE, NUMBERMODE);
		initFunction("Nhap ma de thi", 3, 0, 1);
		while(!exitFunction)
		{
			keypad.getKey();
			if(keySelect == OK){		
				uint8_t codeExam;
				codeExam = convertNum(inputText[0].content);
				if(codeExam == 0)
				{
					drawMessage("Ma de khong hop le, hay nhap lai!", OKTYPE);
					redrawnFunction("Nhap ma de thi", 3, 0);
					continue;
				}
				drawGuiInputAnswer(codeExam, numQuestion);
				exitFunction = true;
				uint8_t resultMessage;
				resultMessage = drawMessage("Luu thanh cong, ban co muon sua ma de khac khong?", OKCANCELTYPE);
				if(resultMessage == CANCEL)
				{
					menuManagementExamQuestion();
					return;
				}
			}
			else if(keySelect == CANCEL){
				uint8_t resultMessage;
				resultMessage = drawMessage("Ban co muon thoat khong?", OKCANCELTYPE);
				if(resultMessage == OK)
				{
					menuManagementExamQuestion();
					return;
				}
				else 
					redrawnFunction("Nhap ma de thi", 3, 0);
			}
			else checkKey();
			keySelect = '\0';
		}
	}
}
void menuDelExamQuestion()
{
}
void menuLoadingTurnOld()
{

}
void menuCreateExamTurn()
{

}
void menuLoadingExamTurn()
{

}
void menuQueryExam()
{

}
void menuSetupTime()
{

}
void menuCheckClient()
{

}
void menuRegisterClient()
{

}
void menuDestroyClient()
{

}
void menuAccessSystem()
{

}

